package com.macrosolution.exdebito

import java.io.Serializable;
import java.util.List;

/**
 * Interview
 * A domain class describes the data object and it's mapping to the database
 */


class Interview implements Serializable{

	/* Default (injected) attributes of GORM */
//	Long	id
//	Long	version
	
	/* Automatic timestamping of GORM */
	Date	dateCreated
	Date	lastUpdated
	User user
	Customer customer
	String  note
	ApprofCessDelCPI acdCPI
	MotiveInterview motiveInterview
	List fileDocument
	
	static hasMany = [fileDocument : FileDocument]
	
	
	
//	static	belongsTo	= []	// tells GORM to cascade commands: e.g., delete this object if the "parent" is deleted.
//	static	hasOne		= []	// tells GORM to associate another domain object as an owner in a 1-1 mapping
//	static	hasMany		= []	// tells GORM to associate other domain objects for a 1-n or n-m mapping
//	static	mappedBy	= []	// specifies which property should be used in a mapping 
	
  
	static	constraints = {
		user nullable:true
		customer nullable:true
		note nullable:true
		acdCPI nullable:true
		motiveInterview nullable:true
		fileDocument nullable:true
    }
	
	static mapping = {
		 customer cascade: 'all-delete-orphan'
		 acdCPI cascade: 'all-delete-orphan'
		 motiveInterview cascade: 'all-delete-orphan'
		 fileDocument cascade: 'delete, all-delete-orphan'
	}
	/*
	 * Methods of the Domain Class
	 */
//	@Override	// Override toString for a nicer / more descriptive UI 
//	public String toString() {
//		return "${name}";
//	}
	
	
	public boolean isEditableByUser(User fromUser){
		User owner = this.user
		List<User> family=fromUser.getFamily()
		boolean result=false
		if(family){
		for(User fam : family){
			if(fam.id.equals(owner.id)){
				result=true;
				break;
			}		
		  }
		}
		return result
	}
	
	
}
